package com.itboye.boyeshoping.fragment

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ListView
import android.widget.TextView

import com.itboye.boyeshoping.R
import com.itboye.boyeshoping.adapter.GoodsListAdapter
import com.itboye.boyeshoping.base.BaseFragment


/**
 * Created by Administrator on 2018/7/6 0006.
 */

class ViewPagerFragment : Fragment(), View.OnClickListener {

     var fragment: ViewPagerFragment? = null
    private  var mActivity: Activity? = null
    //商品列表
    private var type:Int = 0
    private lateinit var defeault: TextView
    private lateinit var salesNums: TextView
    private lateinit var price: TextView

    private lateinit var goodsLv: ListView
    private var adapter: GoodsListAdapter? = null

//    override fun initView(): Int {
//        return R.layout.fragment_viewpagers
//    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        var inflate = inflater!!.inflate(R.layout.fragment_viewpagers, null, false)
        //商品列表
        defeault= inflate!!.findViewById(R.id.defeault) as TextView
        salesNums= inflate!!.findViewById(R.id.salesNums) as TextView
        price= inflate!!.findViewById(R.id.price) as TextView
        goodsLv= inflate!!.findViewById(R.id.goodsLv) as ListView
        return inflate
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        defeault!!.setOnClickListener(this)
        price!!.setOnClickListener(this)
        salesNums!!.setOnClickListener(this)
        adapter = GoodsListAdapter(activity)
        goodsLv!!.adapter = adapter
    }
    //type 分类
    fun newInstance(type:Int,mActivity:Activity): ViewPagerFragment {
        this.type=type
        this.mActivity=mActivity
        fragment = ViewPagerFragment()

        return fragment as ViewPagerFragment
    }


    override fun onClick(p0: View?) {
        when(p0!!.id){
            R.id.defeault->{//默认
                clearState()
                defeault.setTextColor(resources.getColor(R.color.maincolor))
                //请求数据
            }

            R.id.salesNums->{//销量
                clearState()
                salesNums.setTextColor(resources.getColor(R.color.maincolor))

            }

            R.id.price->{ //价格
                clearState()
                price.setTextColor(resources.getColor(R.color.maincolor))
            }
        }

    }

    private fun clearState() {
        defeault.setTextColor(resources.getColor(R.color.taobaotext))
        salesNums.setTextColor(resources.getColor(R.color.taobaotext))
        price.setTextColor(resources.getColor(R.color.taobaotext))

    }

}
